﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity;
using Orktane.Components;

namespace Orktane.Behaviors
{
    public class InputConsoleKeyInfoTrigger 
        : TriggerBase<UIElement>
    {

#region Override

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.KeyDown += new KeyEventHandler(AssociatedObject_KeyDown);
        }

        protected override void OnDetaching()
        {
            AssociatedObject.KeyDown -= new KeyEventHandler(AssociatedObject_KeyDown);
            base.OnDetaching();
        }

#endregion

#region Handlers

        public void AssociatedObject_KeyDown(object sender, KeyEventArgs e)
        {
            var _inputKeyInfo = new ConsoleKeyInfo(e.Key, e.PlatformKeyCode, Keyboard.Modifiers);
            InvokeActions(_inputKeyInfo);
        }

#endregion

    }
}